$(document).ready(function(){
	$('.tipsy').tipsy({gravity: 's'});	
	$("#frmCancelation").validate({				
		errorClass		: "errorMessage",
		errorElement	: "span",
		onfocusout		: false,
		onkeyup			: false,
		rules: {			
			ppassword_can:{
				required						: true,
				passwordValidateForCancelation	: true
			}
		},
		messages: {				
			ppassword_can:{
				required						: password_required,
				passwordValidateForCancelation	: password_invalid
			}
		},		
		errorPlacement: function(label, element) {			
			var id = element.attr("id");			
			label.insertAfter($("#" + id));			
		},
		submitHandler: function(form) {	
			$("#ppassword_can").val("");
			form.submit();
		}
	});	
	$.validator.addMethod("passwordValidateForCancelation", function(){
		var result 			= true;
		var strPassword		= $("#ppassword_can").val();
		
		var strHasPassword	= MD5(MD5(strGeneralCode) + MD5(strPassword));				
		var strUrl 			= HOST_VFRIEND + "valid/isvalidpassword";
		$("#ppassword_can").val("");
		$("#phaspass").val(strHasPassword);
		$.ajax({
			cache	: false,
			async	: false,
			type	: "POST",
			data	: "password=" + strHasPassword,
			url		: strUrl,
			success	: function(response) {
				result = (response == 1) ? true : false;
			}
		});
		return result;								   
	});	
});
editAvatar = function() {
	$.getJSON(				
		HOST_VFRIEND + 'ajax/actbasic?type=15&callback=?',	
		function(response) {							
			var msg	= response['form'];	
			$.blockUI({
				message: msg, 
				css: { 
					textAlgin:'left',
					background:'none',
					border: 'none',
					width:'400px', 
					top: (($(window).height()-400)/2) + 'px', 
					left:(($(window).width()-400)/2) + 'px',
					cursor: 'default',
					zIndex: '10001'
				},
				overlayCSS: {
					cursor: 'default',
					zIndex: '10000'
				}
			});
		}
	);
}
delAvatar = function(strToken) {
	if(confirm(image_del_confirm) == true) {
		document.location.href = HOST_VFRIEND + 'account/delimg?token=' + strToken;
	}
}
uploadAvatar = function() {
	$strImage	= $('#pimage').val();
	$('.errorMessage').hide();
	if(!validateImage($strImage)) {
		$('.errorMessage').show();
		$('.errorMessage').html(image_format);
		return false;
	}
	if(!validateImgSize('pimage')) {
		$('.errorMessage').show();
		$('.errorMessage').html(image_size);
		return false;
	}	
	$('#formUpload').hide();
	$('#formLoading').show().html('<img src="' + HOST_STATICS + 'img/bg/loading-bar.gif" alt="Loading..." width="88" height="7" border="0"/>');	
	$.ajaxFileUpload ({
		url:			HOST_VFRIEND + 'ajax/upload',
		secureuri:		false,
		fileElementId:	'pimage',
		dataType: 		'json',
		data:{
			name:'logan', 
			id:'id'
		},
		success: function (data, status)
		{
			if(typeof(data.error) != 'undefined')
			{
				$('#formLoading').hide();
				$('#formUpload').show();
				if(data.error != '' && data.error == 0) {							
					$('#pimage').val('');
					showUIMessage(data.msg);
					$('#idAvatar').attr('src',data.path);
					$('#avatarAct').show();
				} else {
					alert(data.error);
				}
				
			}
		},
		error: function (data, status, e)
		{
			console.log(e);
			alert(image_error);
		}
	});
}
basicLoad = function(intType, divView, divForm) {
	$('.view').show();
	$('.form').hide();
	$('#'+divView).hide();
	$('#'+divForm).show().html('<img src="' + HOST_STATICS + 'img/bg/loading-bar.gif" alt="Loading..." width="88" height="7" border="0"/>');
	$.getJSON(
		HOST_VFRIEND + 'ajax/actbasic?type=' + intType + '&view=' + divView + '&edit=' + divForm + '&callback=?',		
		function(response) {				
			$('#'+divForm).show().html(response['form']);
		}
	);
}
basicClose = function(divView, divForm) {
	$('#'+divView).show();
	$('#'+divForm).hide();
}
